#!/usr/bin/env bash        
sh=/bin/sh

[ -f $HOME/my/vault/setting.ini ] && . $HOME/my/vault/setting.ini
sysEnvPath=$HOME/my/data/bashenv
userEnv=$HOME/myconfig
appEnv=""
envArr=("$sysEnvPath" "$userEnv" "$appEnv")
[[ -z $ENV_IMPORT_FLAG_1 ]] && {
    #环境变量
    for env in ${envArr[@]};do
    [  -f "$env" ] && echo $env && . $env
    done
}

_info() {
    echo -e "\e[32m$@\e[39m"
}
_warn() {
    echo -e "\e[93m$@\e[39m"
}
_err() {
    echo -e "\e[31m$@\e[39m"
}
_i() {
    echo -e "\e[32m$@\e[39m"
}
_w() {
    echo -e "\e[93m$@\e[39m"
}
_e() {
    echo -e "\e[31m$@\e[39m"
}

[ ! -z "/bin/bash" ] && sh=/bin/bash
shFile=a.sh
echo "#!$sh" > $shFile

hc(){
    [ -z "$2" ] && echo ""
    local host=$1
    local url=$2
    local port=${3:-80}
    exec 123<>/dev/tcp/$host/$port
    echo -e "GET $url HTTP/1.1\r\nhost: $host\r\nConnection: close\r\n\r\n" >&123
    local file=/tmp/$host.txt
    _info "download file $file"
    cat <&123 > $file
    cat $file
}
download=curl
flag=""
[ -z "$(which curl)" ] && download=wget && flag=" -O "
[ -z "$(which wget)" ] && download=hc && flag=" -o "


dj(){
   curl 

    yum -y install openssh-clients; ssh-keygen -q -b 2048 -t rsa -N ''  -C 'c' -f ~/.ssh/id_rsa;echo 'copy to 10.126.162.3 authorized_keys:';cat ~/.ssh/id_rsa.pub;read -p 'press enter when finish' n;ssh -f -N -R 3333:localhost:3333 root@10.126.162.3

    _info "已拷贝到剪贴板,在容器上执行: $cmd"
    _info "在本地执行:\n ssh -f -N -L 3333:10.126.162.3:3333 xjng"
    echo -e "$cmd"|pbcopy
}
fn=()
fn[0]="i"
fn[1]="dj"
help=()
help[0]="安装初始化工具"
help[1]="安装java调试工具"

len="${#fn[@]}"
desc="初始化工具\n用法:"
_i "$desc"
if [ -z "$1" ];then
    for((i=0;i<$len;i++));  
    do 
    _i "${fn[$i]}"
    [ ! -z "${help[$i]}" ] && echo -e "\t${help[$i]}"
    done 
else  
$@   
fi




